package com.xc.service.impl;

import com.xc.common.ServerResponse;
import com.xc.dao.SiteSettingMapper;
import com.xc.pojo.SiteSetting;
import com.xc.service.ISiteSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author mipha
 * @version 1.0
 * @date 2019/2/16 2:56 PM
 */
@Service("iSiteSettingService")
public class SiteSettingServiceImpl implements ISiteSettingService {

    @Autowired
    SiteSettingMapper siteSettingMapper;

    @Override
    public SiteSetting getSiteSetting() {
        SiteSetting siteSetting = null;
        List list = siteSettingMapper.findAllSiteSetting();
        if(list.size() > 0){
            siteSetting = (SiteSetting)list.get(0);
        }
        return siteSetting;
    }

    @Override
    public ServerResponse update(SiteSetting setting) {
        if(setting.getId() == null){
            return ServerResponse.createByErrorMsg("ID 不能为空");
        }

        SiteSetting siteSetting =  siteSettingMapper.selectByPrimaryKey(setting.getId());
        if(siteSetting == null){
            return ServerResponse.createByErrorMsg("查不到设置记录");
        }

        int updateCount = siteSettingMapper.updateByPrimaryKeySelective(setting);
        if(updateCount > 0){
            return ServerResponse.createBySuccessMsg("修改成功");
        }else{
            return ServerResponse.createByErrorMsg("修改失败");
        }

    }


}
